﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _查询测试
{
    class Program
    {
        static void Main(string[] args)
        {

            #region 查询测试
            //using (var db = new BaseContext())
            //{
            //    var list = (from a in db.Student
            //                where a.Id <= 100
            //                select new
            //                {
            //                    StuNum = a.StuNum,
            //                    StuName = a.Name,
            //                    ExamScore = (from b in db.StuFraction
            //                                 where b.StuId == a.Id
            //                                 select new { ExamName = b.CourseName, Score = b.Score, ExamTime = b.ExamTime }
            //                                                                       ).ToList()
            //                }).ToList();


            //    var list2 = list;


            //    var list3 = db.Student.Join(db.StuFraction, g => g.Id, gf => gf.StuId, (g, gu) => new { g, gu }).Select(x => new { x.g.StuNum,x.g.Name,x.gu.CourseName,x.gu.Score });

            //} 
            #endregion

            //List<TestOne> testOnes = new List<TestOne>() {
            //    new TestOne(){ ID=1,Name="张三",Age=18 },
            //    new TestOne(){  ID=2, Name="李四",Age=19},
            //    new TestOne(){ ID=3, Name="小红", Age=20 }
            //};

            //testOnes.FindAll(delegate (TestOne one) { return one.Age > 18; }).ForEach(x => { Console.WriteLine(x.Age + ""); });
            //testOnes.Find(x => x.ID > 2);

            #region 测试lamda 查询 一个实体 结果集是另一个实体
            List<T1> T1List = new List<T1>() {

                new T1(){ T1_1=10, T1_2=10, T1_3=10 },
                new T1(){ T1_1=20, T1_2=20, T1_3=20 },
                new T1(){ T1_1=30, T1_2=30, T1_3=30 }
            };


            List<T2> T2List = T1List.Where(x => x.T1_1 > 10).Select(x =>
            {
                T2 t2 = new T2();
                t2.T2_1 = x.T1_1;
                t2.T2_2 = x.T1_2;
                return t2;
            }).ToList();

            foreach (var item in T2List)
            {
                Console.WriteLine(item.T2_1 + "," + item.T2_2);
            } 
            #endregion


            Console.ReadKey();

        }


    }


    public class T1
    {
        public int T1_1 { get; set; }

        public int T1_2 { get; set; }

        public int T1_3 { get; set; }
    }

    public class T2
    {
        public int T2_1 { get; set; }

        public int T2_2 { get; set; }
    }



    public class TestOne
    {
        public TestOne()
        {
           
        }
        public delegate void WriteDatas(object sender, EventArgs e);
        public event WriteDatas Wirtes;
        public int ID { get; set; }

        public string Name { get; set; }

        public int Age { get; set; }

    }
}
